home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / Generic LW (30 sec Alert) / Generic LaserWriter.c < prev    next >
Encoding:
Text File  |  1996-06-15  |  3.9 KB  |  193 lines  |  [TEXT/MPS ]

  1. /*-----------------------------------------------------------------------------
  2.  
  3.     Generic LaserWriter.c
  4.     
  5.         This part of the driver demonstrates how to force the PostScript
  6.         imaging system to copy its output to a file.
  7.         
  8.      12/18/93 - dmh - Removed IIg-dependencies for b3.
  9.         9/13/93 - dmh - Updated for the b2 seed.
  10.         9/14/93 - dmh - Disabled the PostScript log which was created in
  11.                                         the Extensions folder.
  12.         3/22/94 - dmh - Balanced gxInitialize override with a gxShutDown one.
  13.       6/14/94 - dmh - Added the mystical, magical, 30 second alert.
  14.       8/28/94 - dmh - Finalized for SDK.
  15.         6/14/96 - cn  - Updated to support Universal Interfaces 2.1.
  16.         
  17.     © 1991-1996 Apple Computer Inc.
  18.     
  19. -----------------------------------------------------------------------------*/
  20.  
  21. // If non-zero, we create a PostScript log in the Extensions folder.
  22.  
  23. #define CREATELOG    0
  24.  
  25. #include <GXPrinterDrivers.h>
  26. #include <GXExceptions.h>
  27.  
  28. #define    kCreatorType        'scL2'
  29. #define kMyStatID                gxPrintingDriverBaseID
  30.  
  31.  
  32. extern long A5Size (void);
  33. extern void A5Init (void *);
  34.  
  35.  
  36. // Globals...
  37.  
  38. short gLogRefNum;
  39.  
  40.  
  41. OSErr DriverPostScriptDoPageSetup(    gxFormat theFormat,
  42.                                                                          long     pageindx,
  43.                                                                         gxPostScriptImageDataHdl imageDataHdl )
  44. {
  45.     OSErr status;
  46.     char    *setupcommand = (char *) "\p%% File For Level-I or Level-II.\n";
  47.     
  48.     require(CREATELOG, Not_Logging);
  49.     status = Send_GXBufferData( & setupcommand[ 1 ], setupcommand[ 0 ], 0 );
  50.     nrequire( status, BufferCommandFailed );
  51.     
  52. Not_Logging:
  53.     
  54.     status = Forward_GXPostScriptDoPageSetup( theFormat, pageindx, imageDataHdl );
  55.     ncheck( status );
  56.     
  57. BufferCommandFailed:
  58.     return( status );
  59. }
  60.  
  61.  
  62. OSErr    Do30SecondAlert()
  63. {
  64.     OSErr                        anErr;
  65.     gxStatusRecord    *pStatus;    
  66.     long                        numTicks;
  67.     
  68. // allocate the status record
  69.  
  70.     pStatus = (gxStatusRecord *) NewPtrClear(sizeof(gxStatusRecord));
  71.     anErr = MemError();
  72.  
  73.     if (anErr == noErr ) {
  74.         pStatus->statusOwner        = kCreatorType;
  75.         pStatus->statResId             = kMyStatID;
  76.         pStatus->statResIndex     = 1;
  77.         pStatus->bufferLen            = 0;
  78.  
  79.  
  80. // Tell the Printing Manager to display the 30 second alert
  81.  
  82.         numTicks = TickCount();
  83.  
  84.         do
  85.         {
  86.             anErr = GXAlertTheUser(pStatus);
  87.  
  88.             // wait for 30 seconds.
  89.  
  90.             if ((anErr == noErr) && (pStatus->dialogResult == 0)) {
  91.     
  92.                 Boolean    weBeDone;    
  93.                 
  94.                 weBeDone = (TickCount() - numTicks) >= 30*60;
  95.  
  96.                 if (weBeDone) {
  97.                     pStatus->statResIndex    = 2;
  98.                     anErr = GXAlertTheUser(pStatus);
  99.                     pStatus->dialogResult = ok;
  100.                     
  101.                     }
  102.                 }
  103.                 
  104.             } while ((pStatus->dialogResult == 0) &&  (anErr == noErr));
  105.  
  106.         DisposePtr((Ptr) pStatus);
  107.         }
  108.     return( anErr );
  109. }
  110.  
  111.  
  112. OSErr DriverOpenConnection(void)
  113.     {
  114.         OSErr            status;
  115.                 
  116.         Do30SecondAlert();
  117.         status = Forward_GXOpenConnection();
  118.         nrequire(status, failed_Forward);
  119.         require(CREATELOG, Not_Logging);
  120.  
  121.         status = Create("\pPostScriptLog.ps", 0, 'MPS ', 'TEXT');
  122.         ncheck(status);
  123.         status = FSOpen("\pPostScriptLog.ps", 0, &gLogRefNum);
  124.         ncheck(status);
  125.                     
  126.         status = noErr;
  127.     
  128. Not_Logging:
  129. failed_Forward:
  130.         return(status);    
  131.     
  132.     }//DriverOpenConnection
  133.  
  134.  
  135. OSErr    DriverCloseConnection(void)
  136.     {
  137.         OSErr            status;
  138.         long            j;
  139.         
  140.         status = Forward_GXCloseConnection();
  141.         nrequire(status, failed_Forward);
  142.         require(CREATELOG, Not_Logging);
  143.  
  144.         GetFPos(gLogRefNum, &j);
  145.         SetEOF(gLogRefNum, j);
  146.         FSClose(gLogRefNum);
  147.  
  148. Not_Logging:
  149. failed_Forward:
  150.         return(status);
  151.     }
  152.  
  153.  
  154.  
  155. OSErr    DriverInitialize(void)
  156.     {
  157.         OSErr            status;
  158.         
  159.         status = NewMessageGlobals(A5Size(), A5Init);
  160.         nrequire(status, failed_a5);
  161.  
  162. failed_a5:        
  163.         return(status);
  164.     
  165.     }
  166.  
  167.  
  168. OSErr    DriverShutDown(void)
  169.     {
  170.         DisposeMessageGlobals();
  171.         return noErr;
  172.     }
  173.  
  174.  
  175. OSErr DriverDumpBuffer(gxPrintingBuffer *buffPtr)
  176.     {
  177.         OSErr                status;
  178.         long                count;
  179.                 
  180.         require(CREATELOG, Not_Logging);
  181.         count = buffPtr->size;
  182.         
  183.         status = FSWrite(gLogRefNum, &count, buffPtr->data);
  184.         nrequire(status, failed_Write);
  185.     
  186. Not_Logging:
  187.         status = Forward_GXDumpBuffer(buffPtr);
  188.         ncheck(status);
  189.     
  190. failed_Write:
  191.         return(status);
  192.     
  193.     }